package cumeo89.chii.client.util;

public final class MyArrays {

	private MyArrays() {
		// DO NOTHING
	}

	public static <T> int search(T[] a, T v) {
		int index = a.length - 1;
		while (index >= 0 && !a[index].equals(v)) {
			index--;
		}
		return index;
	}

	public static int search(JSStringArray a, String v) {
		int i = a.length() - 1;
		while (i >= 0 && !v.equals(a.get(i))) {
			i--;
		}
		return i;
	}

	public static <T> boolean contains(T[] a, T v) {
		return search(a, v) >= 0;
	}

	public static boolean contains(JSStringArray a, String v) {
		return search(a, v) >= 0;
	}

	public static String translate(String word, String[] from, String[] to) {
		int i = search(from, word);
		return i < 0 ? null : to[i];
	}

	public static String translate(String word, JSStringArray from,
			JSStringArray to) {
		int i = search(from, word);
		return i < 0 ? null : to.get(i);
	}

}
